<?php

/**
 * 微博群组管理页
 * author yangchao
 * date 2011/05/04
 */

include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/foodv2/inc.php");

//include_once($_SERVER["DOCUMENT_ROOT"] ."/config/foodv2_config.php");
//include_once($_SERVER["DOCUMENT_ROOT"] ."/config/group_app_config.php");


function check_cgi_pro()
{		
	global $g_cgival, $g_pro, $g_show, $config;
	cgi::both($g_cgival['p'],"p",1);
	cgi::both($g_cgival['pcount'],"pcount",10);
	
	$g_cgival['p'] = intval($g_cgival['p']);
	$g_cgival['pcount'] = intval($g_cgival['pcount']);
	
	cgi::both($g_cgival['product_id'],"product_id",0);
	$g_cgival['product_id'] = intval($g_cgival['product_id']);
	
	
	
}
function get_data()
{
	global $g_cgival, $g_pro, $g_show, $pager, $config;
	
	//调用api
	$api_server	= "http://user.henan.sina.com.cn/";// $config["user_center_domain"][$config["current_site_id"]];
	$app_key 	= $config["user_center_app"][$config["current_site_id"]][$config["current_product_id"]]["app_key"];
	$app_secret	= $config["user_center_app"][$config["current_site_id"]][$config["current_product_id"]]["app_secret"];
	$uid = $g_pro['uid'];
	$action_id = 1;
	$product_id = 120;//美食
	$site_id = admin::admin_get_user_site_id();
	$yewu_id = $product_id.$site_id;
	if($site_id == 900)
	{
		$site_id = 0;
	}
	$api = new sina_dfz_lib($app_key,$app_secret,$api_server);
	$data = $api->api_get_message_v2(0,$site_id,$product_id,'',$g_cgival['p'],$g_cgival['pcount']);

	$data = json_decode($data,1);
	
	$g_show["yewu_id"] = $yewu_id;
	$g_show["count"] = $data["count"];
	$g_show["list"] = $data["list"];


	//调用api end
	$max_page = page_bar::get_page_max($g_show["count"], $g_cgival['pcount'], $g_cgival["p"]);
	
	$page_bar_style = array(
			"curt"		=> $g_cgival["p"],
			"max"		=> $max_page,
			"key"		=> "p",
			);

	$g_show["page_bar"] = "<b>{$g_show["count"]}</b> 条记录&nbsp;&nbsp;第{$g_cgival["p"]}页&nbsp;共{$max_page}页&nbsp;" . page_bar::bar2($page_bar_style);
	
	//当前群列表
//	$db_weibo_grou = new db_weibo_group();
//	$group_list = $db_weibo_grou->admin_get_list_by_site_id($site_id,1,1000);
//	
//	foreach ($group_list as $val)
//	{
//		$g_show["group_list"][$val['group_id']] = $val;
//	}


	
}
try
{
	
    admin_check_login();
	admin_check_user_priv("foodv2/message/user_sys_message_list.php");
	check_cgi_pro();
	get_data();

	$g_show["error"] = "0";
	$g_show["errmsg"] = "";
}
catch (Exception $e)
{
	$g_show["error"] = "1";
	$g_show["errmsg"] = $e->getMessage();
}
show_pro();
exit();

function show_pro()
{
	global $g_cgival, $g_pro, $g_show, $smarty, $pager, $config;

	$smarty = p_get_smarty();
	$smarty->assign('g_show', $g_show);
		
	if ($g_show["error"] == "0")
	{
		$smarty->assign('g_show', $g_show);	//版块信息
		
		$smarty->display("foodv2/message/mod_user_sys_message_list.html");

		
	}
	else
	{
		$smarty->display("admin/admin_error.html");//指定错误页面
	}
	
	if(isset($_GET["debug"]))
	{
		echo "<pre>";
		print_r($g_show);
	}


}

?>